#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Time       :   13:09
# Author     : Y4
# Site       : 
# File       : 001 - 打开文件.py
# Software   : PyCharm


'''
open(file, mode='rt', buffering=None, encoding=None, errors=None, newline=None, closefd=True)
    'r'       open for reading (default)
    'w'       open for writing, truncating the file first
    'x'       create a new file and open it for writing
    'a'       open for writing, appending to the end of the file if it exists
    'b'       binary mode
    't'       text mode (default)
    '+'       open a disk file for updating (reading and writing)
    'U'       universal newline mode (deprecated)

'''
# 读取
stream = open('a.txt')
container = stream.read()
print(container)


# 判断文件是否可读
result =  stream.readable()
print(result)           # true

# 读取一行
while True:
    line = stream.readline()
    print(line)  # 读取一行
    if not line:
        break


# 保存在列表中
lines = stream.readlines()
print(lines)                # ['hello world\n', 'hello ketty']


print("-"*80)


# 读取图片
image = open('b.jpg','rb')
container = image.read()
print(container)

